package com.hzb.controoler;

import com.hzb.entity.User;
import com.hzb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * 功能描述
 *
 * @author 和振斌
 * @date 2020/7/31
 * @return
 */
@Controller
@RequestMapping("user")
public class UserController
{
    @Autowired
    private UserService userService;

    /**
     * 登录
     * */
    @PostMapping("login")
    public String  login(User user, HttpSession session){
        User userDb = userService.login(user);
        if(!ObjectUtils.isEmpty(userDb)){
            session.setAttribute("user",userDb);
            return "redirect:/file/showAll";
        }else{
            return "redirect:/index";
        }

    }
}
